package net.zjitc;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Created by Administrator on 2017/9/27.
 */
@WebServlet(name = "HttpServletOne",urlPatterns = "/ServletOne")
public class HttpServletOne extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
       // response.sendRedirect("/test/ServletTwo");//重定向,URI，请求两次，地址栏改变
//       RequestDispatcher rd= request.getRequestDispatcher("/ServletFour");//请求转发，servlet，请求一次，地址栏不变
//      rd.forward(request,response);
      //请求包含
        //相应头在接收的servlet里面设置
        //两个servlet同时响应
        //地址不变
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out=response.getWriter();
        out.write("我是薛泰峰");
        RequestDispatcher rd=request.getRequestDispatcher("/ServletFour");
        rd.include(request,response);
    }
}
